package com.yedean.mall.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yedean.mall.entity.UmsResource;
import com.yedean.mall.mapper.UmsResourceMapper;
import com.yedean.mall.service.IUmsResourceService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 后台资源表 服务实现类
 * </p>
 *
 * @author yedean
 * @since 2022-08-03
 */
@Service
public class UmsResourceServiceImpl extends ServiceImpl<UmsResourceMapper, UmsResource> implements IUmsResourceService {

    @Override
    public IPage<UmsResource> pageResources(Long categoryId, String nameKeyword, String urlKeyword, Integer pageSize, Integer pageNum) {
        Page<UmsResource> page = new Page<>(pageNum, pageSize);

        QueryWrapper<UmsResource> wrapper = new QueryWrapper<>();
        
        if (categoryId!=null){
            wrapper.eq("category_id",categoryId);
        }
        if (StrUtil.isNotEmpty(nameKeyword)){
            wrapper.like("name",nameKeyword);
        }
        if (StrUtil.isNotEmpty(urlKeyword)){
            wrapper.like("url",urlKeyword);
        }
        return baseMapper.selectPage(page,wrapper);
        
    }

    @Override
    public Map<String, List<String>> initResourceRolesMap() {
        return null;
    }
}
